<template>
  <el-container>
    <el-header>
      <div class="logo">
        <img src="@/assets/vue.svg" srcset="" />
        <h1>青芒电商后台管理系统</h1>
      </div>
      <el-button @click="out">退出</el-button>
    </el-header>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="200px">
        <!-- 导航栏6  unique-opened 每次只开一个子菜单,index 必须唯一,字符串 router,index就是path  -->
        <el-menu background-color="#333744" text-color="#fff" active-text-color="#409EFF" router v-for="aa in menulist">
          <el-sub-menu index="1">
            <template #title>
              <span>{{ aa.authName }}</span>
            </template>
            <el-menu-item :index="'/home/' + bb.path" v-for="bb in aa.children">{{ bb.authName }}</el-menu-item>
          </el-sub-menu>
        </el-menu>
      </el-aside>
      <el-main>
        <!-- 二级路由 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>


<script setup lang="ts">
import { useRouter } from 'vue-router'
import request from '@/util/request'
import { ref } from 'vue'
let menulist: any = ref([])
const getMenu = async () => {
  const data = await request({
    url: '/menus',
    method: 'GET',
    // 在请求方法中,添加请求头
    // headers: {
    //   Authorization: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjUwMCwicmlkIjowLCJpYXQiOjE3MTY3Mjg2NjcsImV4cCI6MTcxNjgxNTA2N30.n2wtotLWBORo-LP00FE77KGSRshXrjsgM_sr_ZlnsRc'
    // },
  })
  menulist.value = data.data
}
getMenu()
const router = useRouter()
const out = () => {
  router.push('/')
}
</script>


<style scoped lang="scss">
.el-container {
  height: 100vh;
}


.el-header {
  background-color: #373D41;
  color: #fff;
  display: flex;
  justify-content: space-between;
  padding: 0px;

  .logo {
    overflow: hidden;
    height: 40px;

    display: flex img {
      margin-top: -20px;
      width: 200px;
      height: 200px;
    }


    h1 {
      height: 60px;
      font-size: 20px;
      line-height: 60px;
    }
  }


  .el-button {
    height: 40px;
    margin-top: 10px;
    margin-right: 40px;
  }
}


.el-aside {
  background-color: #333744;


  .el-menu {
    border: none;
  }
}


.el-main {
  background-color: #EAEDF1;
}
</style>
